dalhousie_rovfandomcom-20200215-history
Git Workflow
Though git has many useful tools, typical usage will follow a similar pattern. This article will outline and explain these commands. This page assumes that users have completed the steps outlined on the git page and are in the git bash command line. Cloning a Repository The first step to working on any git project is to clone the repository. This can be done by running the command: git clone https://gitlab.com/dalrov/Dalhousie-ROV-Code-2016.git You should be prompted for your gitlab username and password. If everything went alright, you should now have a folder called Dalhousie-ROV-Code-2016 in your current folder. cd Dalhousie-ROV-Code-2016 will bring you into the newly downloaded folder. From here, git commands will act on this repository. Setting up Git Before being able to use the useful features of git, you must set up your user credentials. The commands: git config --global user.name "Your Name Comes Here" git config --global user.email you@yourdomain.example.com will take care of this. This only has to be done after installing git for the first time. Any repos you clone from then on should work fine without doing this again. Branching Instead of making changes directly to the "master" (main) branch of the code, you should instead make a branch of master. This means that changes you make to the code will not affect the master branch until it is later merged back into master. This makes it easy to organize changes to the code and prevent the main code from being changed until the new code has been properly reviewed. First move into the branch that you want to branch from (for example, master): git checkout master Then create the branch: git branch branch_name Then move into your new branch: git checkout branch_name And finally tell gitlab that you've made a new branch: git push --set-upstream origin branch_name You are now ready to make changes to the code. Uploading Changes to Gitlab Once you've made changes to the code, you need to update the repository on your computer, then update the one on gitlab. First, tell git that you've made changes (it will find the changes you made, so there's no need to tell it which files were changed): git add . Next update your local repository, including a message about what was changed. git commit -m "your message here" If no new files were added (i.e. the only changes are in existing files), the previous two commands can instead be: git commit -am "your message here" Finally, tell gitlab about the changes that you've made: git push Getting Changes From Gitlab Git also allows for you to update your local repository from the gitlab one. This can be done for a single branch with the command: git pull To update all of the branches: git pull --all Full Example Going over the same example as in the git tutorial: git clone https://gitlab.com/dalrov/Dalhousie-ROV-Code-2016.git cd Dalhousie-ROV-Code-2016 git config --global user.name "Alex Dewar" git config --global user.email Alex.Dewar@dal.ca git branch Alex_Text_File git checkout Alex_Text_File git push --set-upstream origin Alex_Text_File then, after adding a text file: git add . git commit -m "Added a text file" git push